package com.py.gs.tools;

/**
 * 
 * 2017年10月25日
 * 
 */
public class LocalRandom
{
	private double seed = 1;
	private double a = 98765;
	private double c = 10234567;
	private double m = 42949672;

	public LocalRandom() {
		randomseed(System.currentTimeMillis());
	}
	
	//设置随机种子
	public void randomseed(double s){
		seed = s;
	}

	//返回随机整数数
	public double randomNext(double max){
		double next = (seed * a + c) % m;
		seed = next;
		next = next % max + 1;
		return next;
	}

	//返回随机整数数
	public double randomNext(){
		double next = (seed * a + c) % m;
		seed = next;
		return next;
	}

	// 获取随机种子
	public double getRandomseed( ){
		return seed;
	}

	//随机浮点数
	public double randomFloat( double min, double max ){
		double b = 10000000;
		double minLong = min * b;
		double maxLong = max * b;
		double minus = maxLong - minLong;
		double d = randomNext(minus) + minLong;
		return d / b;
	}
	
//	public static void main(String[] args) {
//		LocalRandom r = new LocalRandom();
//		r.randomseed(12354534f);
//		
//		for (int i = 0; i < 10; i++) {
//			System.out.println(r.randomNext(1000));
//		}
//	}
}
